<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <title>问卷调查</title>
    <script src="${js}/jquery-1.9.1.min.js"></script>
</head>
<body>
    <form method="get" action="${ctx}/questionnaire/toAddTitle">
        类型:<select id="type" name="type" onchange="changeSelect(this, 'title')">
                <option>请选择</option>
                <option value="1">血压</option>
                <option value="2">血糖</option>
            </select>
        <input type="submit" value="添加问卷">
    </form>

    <form method="get" action="${ctx}/questionnaire/toAddSubtitle">
        问卷:<select id="title" name="titleId" onchange="changeSelect(this, 'subtitle')">

    </select>
        <input type="submit" value="添加子问卷">
    </form>

    <form method="get" action="${ctx}/questionnaire/toAddQuestion">
        子问卷:<select id="subtitle" name="subtitleId" onchange="changeSelect(this, 'question')">

    </select>
        <input type="submit" value="添加问题">
    </form>

    <form method="get" action="${ctx}/questionnaire/toAddOption">
        问题:<select id="question" name="questionId" onchange="changeSelect(this, 'option')">

    </select>
        <input type="submit" value="添加选项">
    </form>

        选项:<select id="option"> </select>
    <script>
        function changeSelect(obj, name) {
            $.post("${ctx}/questionnaire/getList", {name: name, type: obj.value, titleId: obj.value,
                                                    questionId:obj.value, subtitleId:obj.value},
                function(data){
                    $("#"+name).empty();
                    $("#"+name).append("<option>请选择</option>");
                    for (var i=0; i<data.data.length; i++) {
                        var d = data.data[i];
                        $("#"+name).append("<option value='"+d.value+"'>"+d.text+"</option>");
                    }
                }, "json")
        }
    </script>
</body>
</html>


